package org.ainlolcat.ainscience.utils;

import org.ainlolcat.ainscience.Controller;

/**
 * @author ainlolcat
 *         Date: 4/3/14
 */
public class PathUtils {

    public static String getOOBTemplatesPath()
    {
        String templatePath = PropertiesUtils.getProperty("oobtDir");
        return templatePath!=null ? templatePath : "./templates";
    }

    public static String replaceMacros(String path){
        String home = Controller.getInstance().getProject().getHomeDir();
        String data = PropertiesUtils.getProperty("dataDir");
        data = (data != null ? data : home);

        String newPath = path.replace("%HOME%", home);
        newPath = newPath.replace("%DATA%", data);
        while (true){
            if (newPath.indexOf("%") >= 0){
                int start = newPath.indexOf("%");
                int end = newPath.indexOf("%", start+1);
                String macros = newPath.substring(start+1, end);
                System.out.println(macros);
                newPath = newPath.replace("%" + macros + "%", PropertiesUtils.getProperty(macros));
            } else break;
        }
        return newPath;
    }

}
